# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :create_app.py
# @Time      :2022/5/27 0027 14:43
# @Author    :何胜利
from flask import Flask
from flask_cors import CORS

from common.utils.jwt_auth import jwt_authentication
from models import db
from views.channel import channel_bp
from views.comments import comment_bp
from views.users import user_bp


def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)

    db.init_app(app)

    cors = CORS(app)

    # 用请求钩子校验token
    app.before_request(jwt_authentication)

    app.register_blueprint(user_bp)
    app.register_blueprint(channel_bp)
    app.register_blueprint(comment_bp)

    return app
